package com.huan;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class Test4_Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost",10001);
        System.out.println("连接成功"+socket);
        try (InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream())){
            char[] chars = new char[1024];
            int length = -1;
            while ((length = inputStreamReader.read(chars,0,chars.length))!=-1){
                String s = new String(chars,0,length);
                System.out.println(s);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("与服务器断开连接");
        socket.close();
    }
}
